package com.vic.kjlink.order.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonFormat;

import pers.vic.boot.base.model.BaseEntity;

/**
 * 开启点餐表 实体类
 * 
 * @author Vic.xu
 */
public class Start extends BaseEntity {

    private static final long serialVersionUID = 1L;

    /**
     * 日期
     */
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date date;

    /**
     * 标题
     */
    private String title;

    /**
     * 结束时间
     */
    @JsonFormat(pattern = "HH:mm", timezone = "GMT+8")
    @DateTimeFormat(pattern = "HH:mm")
    private Date endTime;

    /**
     * 配置的套餐的详情
     */
    private List<StartDetail> details = new ArrayList<>();

    public String getEndTimeStr() {
        if (endTime == null) {
            return "";
        }
        return DateFormatUtils.format(endTime, "HH:mm");
    }

    /***************** set|get start **************************************/
    /**
     * set：日期
     */
    public Start setDate(Date date) {
        this.date = date;
        return this;
    }

    /**
     * get：日期
     */
    public Date getDate() {
        return date;
    }

    /**
     * set：标题
     */
    public Start setTitle(String title) {
        this.title = title;
        return this;
    }

    /**
     * get：标题
     */
    public String getTitle() {
        return title;
    }

    /**
     * set：结束时间
     */
    public Start setEndTime(Date endTime) {
        this.endTime = endTime;
        return this;
    }

    /**
     * get：结束时间
     */
    public Date getEndTime() {
        return endTime;
    }

    public List<StartDetail> getDetails() {
        return details;
    }

    public void setDetails(List<StartDetail> details) {
        this.details = details;
    }

    /**
     * 校验状态是否合法： 只检验打开的状态 的时间是否在范围内
     * 
     * @return
     */
    public boolean isLegalStatus() {
        if (enable == null || !enable) {
            return false;
        }
        Date today = new Date();
        if (!DateUtils.isSameDay(today, date)) {
            return false;
        }
        int now = Integer.parseInt(DateFormatUtils.format(today, "HHmm"));
        int end = Integer.parseInt(DateFormatUtils.format(endTime, "HHmm"));
        if (now >= end) {
            return false;
        }
        return true;
    }
    /***************** set|get end **************************************/
}
